App({
  onLaunch: function () {
    tt.login({
      success(res) {
      console.log(`login调用成功${res.code} ${res.anonymousCode}`);
      var code = res.code;
      var anonymous_code = res.anonymousCode;

      let task = tt.request({
        url: "https://developer.toutiao.com/api/apps/jscode2session",
        data: {
          appid: "tt9dcdeb7002e7de73",
          secret: "800138e47b81b1c5938c09c217094a70fade0166",
          code: code,
          anonymous_code: anonymous_code
        },
        header: {
          "content-type": "application/json"
        },
        success(res) {
          console.log(`request调用成功 ${res}`);
          console.log(res);
          var session_key = res.data.session_key;
          var openid = res.data.openid;
          var anonymous_openid = res.data.anonymous_openid;
          console.log(openid,"openid")
          try {
            tt.setStorageSync("openid", openid);
          } catch (error) {
            console.log(`setStorageSync调用失败`);
          }

          // tt.checkSession({
          //   success() {
          //     console.log(`session未过期`);


          //     tt.getUserInfo({
          //       success(res) {
          //         console.log(`getUserInfo 调用成功 ${res.userInfo}`);
          //         console.log(res.userInfo);

          //         tt.request({
          //           url: 'https://dycps.aikeai.group/testService/getUserInfo', // 目标服务器url
          //           method: 'post',
          //           data: {
          //             nickname: res.userInfo.nickName,
          //             img: res.userInfo.avatarUrl,
          //             openid: openid,
          //             telephone: 123456
          //           },
          //           success: (res) => {
          //             console.log(res,"第一次上传res")
          //           }
          //         });
          //       },
          //       fail(res) {
          //         console.log(`getUserInfo 调用失败`);
          //       }
          //     });
          //   },
          //   fail() {
          //     console.log(`session已过期，需要重新登录`);
          //   }
          // });
          
        },
        fail(res) {
          console.log(`request调用失败`);
        }
      });
      
      },
      fail(res) {
      console.log(`login调用失败`);
      }
    });
  }
})
